﻿-- =============================================
-- Author:		zengfei
-- Create date: 04m/18/2013
-- Description:	根据查询条件读取相应的进货单资料
-- =============================================
CREATE PROCEDURE [dbo].[Usp_SelectPurchaseByCondition]
	@p_PurchaseNo	varchar(30),
	@p_ReferenceNo	varchar(30),
	@p_VendorNo		varchar(8),
	@p_Warehouse	int,
	@p_Buyer		varchar(20),
	@p_EntryDate	datetime,
	@p_InvoiceStatus	bit
AS
select * 
	from PurchaseMaster 
	where (case when @p_PurchaseNo is null then 1 else (case when PurchaseNo = @p_PurchaseNo then 1 else 0 end) end) = 1 and
			(case when @p_ReferenceNo is null then 1 else (case when ReferenceNo = @p_ReferenceNo then 1 else 0 end) end) = 1 and
			(case when @p_vendorNo is null then 1 else (case when VendorNo = @p_VendorNo then 1 else 0 end) end) = 1 and 
			(case when (@p_Warehouse is null or @p_Warehouse = 0)  then 1 else (case when ReceivedWH = @p_Warehouse then 1 else 0 end) end) = 1 and 
			(case when @p_Buyer is null then 1 else (case when Buyer = @p_Buyer then 1 else 0 end) end) = 1 and 
			(case when @p_EntryDate is null then 1 else (case when EntryDate = @p_EntryDate then 1 else 0 end) end) = 1